import tool from '@/utils/tool';
export default {
    namespaced: true,
    state: {
        ACCOUNT_TYPES:{
            1:'订阅号',
            2:'服务号',
            3:'小程序',
            4:'移动应用'
        },
        accountList:[],
        selectedAppId:''
    },
    mutations: {
      updateAccountList (state, list) {
        state.accountList = list
        if(!list.length)return
        if(!state.selectedAppId){
          let appIdCookie  = tool.cookie.get('appId')
          let selectedAppId = appIdCookie?appIdCookie:list[0].appId
          this.commit('wxAccount/selectAccount',selectedAppId)
        }
      },
      selectAccount (state, appId) {
        tool.cookie.set('appId',appId)
        let oldAppId = state.selectedAppId
        state.selectedAppId = appId
        if(oldAppId){//切换账号时刷新网页
          location.reload();
        }
      },
    }
  }
  